package leetcode_2001_2100;

import java.util.PriorityQueue;

public class LeeCode_2064 {
    public static void main(String[] args) {
//        System.out.println(minimizedMaximum(6, new int[]{11, 6}));
//        System.out.println(minimizedMaximum(1, new int[]{100000}));
        System.out.println(minimizedMaximum(1, new int[]{1}));
    }
    private static int minimizedMaximum(int n, int[] quantities) {
        int r = 0, l = 1;
        for (int quantity : quantities) {
            r = Math.max(r, quantity);
        }
        while (l < r){
            int m = l + (r - l) / 2;
            if (check(n, m, quantities)){
                r = m;
            }else {
                l = m + 1;
            }
        }
        return l;
    }
    private static boolean check(int n, int min, int[] q){
        int c = 0;
        for (int i : q) {
            c += i / min;
            i %= min;
            if (i > 0)
                c++;
        }
        return c <= n;
    }
}